using UnityEngine;
using System.Collections;

public class GameController : MonoBehaviour 
{

	public Rigidbody leaf;
		
	private Vector3 mousePos;
	private float sDrag = 0;
	private float uDrag = 0;
	private float sDiff;
	private float uDiff;
	
	void Start () 
	{
		Physics.gravity = new Vector3(0.0f, 0.0f, -5.8f);	
	}
	
	
	void Update () 
	{
		if(Input.GetKey(KeyCode.R))
			Application.LoadLevel(Application.loadedLevel);

		if(Input.GetMouseButtonDown(0))
		{
			mousePos = Camera.mainCamera.ScreenToWorldPoint(Input.mousePosition);
			mousePos.y = 1;
			leaf.AddExplosionForce(10, mousePos, 10);
		}
		sDiff = Vector3.Dot(leaf.transform.right, Physics.gravity);
		uDiff = Mathf.Abs(sDiff);
		Debug.Log(sDiff);
		leaf.drag = 10/(uDiff+1);
		leaf.AddForce(leaf.transform.forward*(uDiff/10), ForceMode.Force);

		
		if(sDiff > 0)
			leaf.transform.RotateAround(leaf.transform.up, -uDiff/200);
		else
			leaf.transform.RotateAround(leaf.transform.up, uDiff/200);
		
	}
}
